<template>
  <div class="home">
    <transition name="fade" >
      <header class="show" v-if="show">
        <div class="kefu"></div>
        <input type="text" class="find" placeholder="输入关键字搜索作品">
        <a href="" class="info"></a>
        <div class="container">
          <router-link to="/home/home_rec" class="nav">推荐</router-link>
          <router-link to="/home/home_rm" class="nav">入门</router-link>
          <router-link to="/home/home_ql" class="nav">潜力</router-link>
          <router-link to="/home/home_mz" class="nav">名作</router-link>
          <router-link to="/home/home_jj" class="nav">家居</router-link>
        </div>
      </header>
    </transition>
    <transition name="fade">
      <header class="hidden" v-if="!show">
        <router-link to="/home/home_rec" class="nav">推荐</router-link>
        <router-link to="/home/home_rm" class="nav">入门</router-link>
        <router-link to="/home/home_ql" class="nav">潜力</router-link>
        <router-link to="/home/home_mz" class="nav">名作</router-link>
        <router-link to="/home/home_jj" class="nav">家居</router-link>
        <div class="search"></div>
      </header>
    </transition>
    <router-view />
    <!-- 路由出口 -->
  </div>
</template>

<script>
export default {
  name: 'Home',
  data () {
    return {
      msg: '',
      show:true
    }
  },
  mounted () {
    window.addEventListener('scroll',this.getScroll)
  },
  methods: {
    getScroll () {
      // 页面高度
      var h = document.documentElement.scrollTop;
      if(h >= 50){
        this.show = false
        // console.log(document.documentElement.scrollTop)
      }else{
        this.show = true
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
  .fade-enter-active,.fade-leave-active{
    transition: opacity 1s;
  }
  .fade-enter,.fade-leave-to{
    opacity:0;
  }
  header.show{
    width: 100%;
    height: 76px;
    background-color: rgba(0, 0, 0, 0.1);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    padding-top: 14px;
    .kefu{
      float: left;
      width: 12%;
      height: 36px;
      background-image: url(../assets/img/public/headerKefuB.png);
      background-repeat: no-repeat;
      background-size: 30px;
      background-position: center center;
    }
    .find{
      float: left;
      width: 72%;
      height: 30px;
      border:none;
      outline:none;
      padding-left: 10px;
    }
    .info{
      width: 12%;
      height: 36px;
      background-image: url(../assets/img/public/znx.png);
      background-repeat: no-repeat;
      background-size: 30px;
      background-position: center center;
      float: left;
    }
    .container{
      display: flex;
      justify-content: space-around;
    }
    .nav{
      display: inline-block;
      color: #fff;
      height: 36px;
      text-align: center;
      line-height: 36px;
      box-sizing: border-box;
      float: left;
    }
    .router-link-active{
      border-bottom:2px solid #fff;
    }
  }
  header.hidden{
    width: 100%;
    height: 50px;
    background-color: #fff;
    position: fixed;
    top:0;
    z-index: 100;
    display: flex;
    justify-content: space-around;
    .nav{
      display: inline-block;
      color: #000;
      width: 40px;
      height: 48px;
      text-align: center;
      line-height: 52px;
      box-sizing: border-box;
      float: left;
    }
    .router-link-active{
      border-bottom:2px solid #000;
    }
    .search{
      width: 40px;
      height: 50px;
      // background-color: #0f0;
      background-image: url(../assets/img/home/ss.png);
      background-repeat: no-repeat;
      background-size: 24px;
      background-position: right center;
    }
  }
</style>
